<!--
 * @Author: Vi卡农
 * @Date: 2020-02-24 10:26:02
 * @LastEditTime: 2020-05-12 16:50:28
 * @Description: -合同图片-
 * @FilePath: \cshf_admin\src\views\modules\contract\contractimage.vue
 -->
<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-contract__contractimage}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-row>
          <el-col :span="19">
            <el-form-item>
              上传日期：
              <el-date-picker
                v-model="dataForm.createDates"
                type="date"
                placeholder="开始时间"
                value-format="yyyy-MM-dd"
                style="width:136px"
              ></el-date-picker>
              {{' -'}}
              <el-date-picker
                v-model="dataForm.createDatee"
                type="date"
                placeholder="结束时间"
                value-format="yyyy-MM-dd"
                style="width:136px"
              ></el-date-picker>
            </el-form-item>

            <el-form-item>
              部门：
              <el-cascader
                class="FormSelect"
                v-model="deptSelectVal"
                :options="this.$store.state.DeptList"
                :show-all-levels="false"
                @change="deptIdChange"
                :props="deptProps"
                ref="myCascader"
                clearable
              ></el-cascader>-
              <el-select v-model="dataForm.userId" placeholder="人员" class="FormSelect" clearable>
                <el-option
                  v-for="item in maintainList"
                  :key="item.id"
                  :label="item.realName"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>

            <el-form-item>
              图片类型
              <ren-select
                v-model="dataForm.imageType"
                dict-type="contractImageType"
                placeholder="图片类型"
                class="FormSelect"
                clearable
              ></ren-select>
            </el-form-item>

            <el-form-item>
              审核：
              <ren-select
                v-model="dataForm.examine"
                dict-type="examine"
                placeholder="审核类型"
                class="FormSelect"
              ></ren-select>
            </el-form-item>
            <el-form-item>
              <el-button
                v-if="$hasPermission('contract:contractimage:delete')"
                type="danger"
                @click="deleteHandle()"
              >{{ $t('deleteBatch') }}</el-button>
            </el-form-item>

            <el-button type="primary" @click="updateExamineList()">一键审核</el-button>
          </el-col>

          <el-col :span="5">
            搜索：
            <el-input
              placeholder="请输入内容"
              v-model="dataForm.search"
              class="input-with-select"
              @keyup.enter.native="getDataList"
              clearable
              style="width:70%"
            >
              <el-button slot="append" icon="el-icon-search" @click="getDataList"></el-button>
            </el-input>
          </el-col>
        </el-row>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        style="width: 100%;"
      >
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="contractId" label="合同编号" header-align="center" align="center">
          <template slot-scope="scope">{{"HT"+scope.row.contractId}}</template>
        </el-table-column>

        <el-table-column prop="type" label="类型" header-align="center" align="center">
          <template slot-scope="scope">{{$getDictLabel("contractImageType",scope.row.imageType)}}</template>
        </el-table-column>
        <el-table-column prop="title" label="备注" header-align="center" align="center"></el-table-column>
        <el-table-column prop="url" label="地址" header-align="center" align="center" width="180">
          <template slot-scope="scope">
            <el-image
              class="tabImgDiv"
              :src="scope.row.url"
              :preview-src-list="new Array(scope.row.url)"
            ></el-image>
          </template>
        </el-table-column>

        <el-table-column prop="examine" label="审核" header-align="center" align="center">
          <!-- <template slot-scope="scope">{{$getDictLabel("examine",scope.row.examine)}}</template> -->
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.examine"
              @change="tabExamineChange(scope.row)"
              :active-value="1"
              :inactive-value="0"
              :disabled="!$hasPermission('contract:contractimage:updateExamine')"
            ></el-switch>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="sort" label="排序" header-align="center" align="center"></el-table-column> -->
        <el-table-column prop="userName" label="上传人" header-align="center" align="center"></el-table-column>
        <el-table-column prop="deptName" label="上传部门" header-align="center" align="center"></el-table-column>
        <el-table-column prop="createDate" label="上传时间" header-align="center" align="center"></el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="90"
        >
          <template slot-scope="scope">
            <!-- <el-button
              v-if="$hasPermission('contract:contractimage:update')"
              type="text"
              size="small"
              @click="addOrUpdateHandle(scope.row.id)"
            >{{ $t('update') }}</el-button> -->
            <el-button
              v-if="$hasPermission('contract:contractimage:delete')"
              type="text"
              size="small"
              @click="deleteHandle(scope.row.id)"
            >{{ $t('delete') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="ZWbox"></div>
      <div class="paginationBox">
        <el-pagination
          :current-page="page"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="limit"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="pageSizeChangeHandle"
          @current-change="pageCurrentChangeHandle"
        ></el-pagination>
      </div>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./contractimage-add-or-update";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/contract/contractimage/page",
        getDataListIsPage: true,
        exportURL: "/contract/contractimage/export",
        deleteURL: "/contract/contractimage",
        deleteIsBatch: true
      },
      dataForm: {
        id: "",
        examine: "", //审核状态
        createDates: "",
        createDatee: "",
        deptId: "", //部门
        userId: "",
        search: "",
        imageType: ""
      },
      deptSelectVal: "",
      deptProps: {
        value: "id",
        label: "name",
        checkStrictly: true
      },
      maintainList: this.$store.state.maintainList
    };
  },
  components: {
    AddOrUpdate
  },
  methods: {
    //审核
    tabExamineChange(row) {
      this.$http
        .put(
          `/contract/contractimage/updateExamine`,
          {},
          {
            params: {
              id: row.id,
              examine: row.examine
            }
          }
        )
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.$message.success("更改成功");
        })
        .catch(() => {});
    },
    //一键审核
    updateExamineList() {
      let _this = this;
      let arr = [];
      for (let i = 0; i < _this.dataListSelections.length; i++) {
        const element = _this.dataListSelections[i];
        arr.push(element.id);
      }
      this.$http
        .post(
          "/contract/contractimage/updateExamineList",
          {},
          {
            params: {
              ids: arr.join()
            }
          }
        )
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.$message.success("审核成功");
          this.getDataList();
        })
        .catch(() => {});
    },
    deptIdChange(val) {
      let a = "";
      if (this.$refs.myCascader.getCheckedNodes()[0]) {
        a = this.$refs.myCascader.getCheckedNodes()[0].value;
        this.dataForm.deptId = a;
        this.getUserList(a);
      } else {
        this.dataForm.deptId = "";
      }
    },
    // 获取部门员工列表
    getUserList(deptId) {
      let _this = this;
      this.$http
        .get(`/sys/user/deptUserList`, {
          params: {
            deptId: deptId
          }
        })
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          _this.maintainList = res.data;
        })
        .catch(() => {});
    },
  },
   watch: {
    dataForm: {
      handler(nowVal, oldVal) {
        this.getDataList();
      },
      deep: true
    }
  }
};
</script>
